import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-14
 * Time: 9:08
 */
class Solution3 {
    public String largestNumber(int[] nums) {
        int n = nums.length;

        String[] strs = new String[n];

        //优化：将数字转化成字符串
        for(int i = 0; i < n; i++) {
            strs[i] = ""+nums[i];
        }

        Arrays.sort(strs,(a, b)->{
            return (b+a).compareTo(a+b);
        });

        StringBuilder ret = new StringBuilder();

        for(int i = 0; i < n; i++) {
            ret.append(strs[i]);
        }

        if(ret.charAt(0) == '0') {
            return "0";
        }
        return ret.toString();
    }
}
